import os
import django
from django.conf import settings
from environ import DataBaseEnv


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': DataBaseEnv.DB_NAME,
        'USER': DataBaseEnv.DB_USER,
        'PASSWORD': DataBaseEnv.DB_PASSWORD,
        'HOST': DataBaseEnv.DB_HOST,
        'PORT': DataBaseEnv.DB_PORT,
    }
}

INSTALLED_APPS = [
    'django.contrib.contenttypes',  
    'django.contrib.auth',
    'db',
]

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
AUTH_USER_MODEL = 'db.User'

settings.configure(
    DEBUG=True,
    DATABASES=DATABASES,
    INSTALLED_APPS=INSTALLED_APPS,
    DEFAULT_AUTO_FIELD=DEFAULT_AUTO_FIELD,
    AUTH_USER_MODEL=AUTH_USER_MODEL,
)

# 手动指定应用配置，解决独立使用ORM时的路径问题
from django.apps import apps
apps.populate(INSTALLED_APPS)

django.setup()